//
//  NSDate+FormatConversion.m
//  QuXiang
//
//  Created by Duncan on 2020/6/28.
//  Copyright © 2020 NanHuaiZi. All rights reserved.
//

#import "NSDate+FormatConversion.h"

@implementation NSDate (FormatConversion)

/// 传进时间戳字符串，返回日期 ymd
+ (NSString *)getStringWithTimeString:(NSString *)timeString format:(NSString *)format {
    NSTimeInterval interval = [timeString doubleValue];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:format ?: [NSDate jk_ymdFormat]];
    NSString *dateStr = [formatter stringFromDate:date];
    return dateStr;
}

/// 获取时间戳字符串，10位，秒
+ (NSString *)getTimeStringToSecond {
    NSDate *date = [NSDate dateWithTimeIntervalSinceNow:0];
    NSTimeInterval time = [date timeIntervalSince1970];
    NSString *timeString = [NSString stringWithFormat:@"%.0f", time];
    return timeString;
}

/// 获取时间，年月日，时分秒，毫秒
+ (NSString *)getNowTimeFormatStringToMillisecond {
    NSDate *currentDate = [NSDate date];
    NSTimeInterval timeIntervalSince1970 = [currentDate timeIntervalSince1970] * 1000;
    return [NSDate kj_timeWithTimestamp:timeIntervalSince1970 format:@"yyyy-MM-dd HH:mm:ss.SSS"];
}

#pragma mark ------- 分别获取yyyy-MM-dd/HH:mm:ss/yyyy-MM-dd HH:mm:ss格式的字符串 -------

+ (NSString *)jk_ymdFormat {
    return @"yyyy-MM-dd";
}

+ (NSString *)jk_hmsFormat {
    return @"HH:mm:ss";
}

+ (NSString *)jk_ymdHmsFormat {
    return [NSString stringWithFormat:@"%@ %@", [self jk_ymdFormat], [self jk_hmsFormat]];
}

@end
